package cn.edu.ncut.cs.springboot.petmanagementsystem.service.Impl;

import cn.edu.ncut.cs.springboot.petmanagementsystem.mapper.PetBreedMapper;
import cn.edu.ncut.cs.springboot.petmanagementsystem.pojo.PetBreed;
import cn.edu.ncut.cs.springboot.petmanagementsystem.service.PetBreedService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 宠物品种服务实现类
 */
@Service
@RequiredArgsConstructor
public class PetBreedServiceImpl implements PetBreedService {
    
    private final PetBreedMapper petBreedMapper;
    
    @Override
    public Page<PetBreed> getBreedList(int page, int size, String petType) {
        Page<PetBreed> pageParam = new Page<>(page, size);
        LambdaQueryWrapper<PetBreed> wrapper = new LambdaQueryWrapper<>();
        
        // 只查询启用的品种
        wrapper.eq(PetBreed::getStatus, 1);
        
        // 如果指定了宠物类型，则过滤
        if (petType != null && !petType.isEmpty()) {
            wrapper.eq(PetBreed::getPetType, petType);
        }
        
        // 按名称排序
        wrapper.orderByAsc(PetBreed::getName);
        
        return petBreedMapper.selectPage(pageParam, wrapper);
    }
    
    @Override
    public PetBreed getBreedDetail(Long id) {
        return petBreedMapper.selectById(id);
    }
}
